/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entities.OderFood;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author TANGQUOCTUAN
 */
@Stateless
public class OderFoodFacade extends AbstractFacade<OderFood> implements OderFoodFacadeLocal {

    @PersistenceContext(unitName = "eProject_Tunga_Restaurant-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public OderFoodFacade() {
        super(OderFood.class);
    }

    public List getAllOrderFood() {
        Query r = em.createNamedQuery("OderFood.findAll");
        return r.getResultList();
    }

    public List getIDOrderFood(Integer id) {
        Query r = em.createNamedQuery("OderFood.findByOderFoodID");
        r.setParameter("oderFoodID", id);
        return r.getResultList();
    }

    public boolean updateOrderFood(Integer id, Boolean status) {
        OderFood o = em.find(OderFood.class, id);

        if (o == null) {
            return false;
        }
        o.setStatus(status);
        em.persist(o);
        return true;
    }

    public List<OderFood> reportShowBookRoom(Date fromdate, Date todate) {
        List<OderFood> list = new ArrayList<OderFood>();
        Query r = em.createNamedQuery("OderFood.findReportOrder");
        r.setParameter("fromdate", fromdate);
        r.setParameter("todate", todate);
        return list = r.getResultList();
    }
}
